package com.ys.controller.api.amazonorder;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.amazonorder.TbBaseinfoSpcz;
import com.ys.service.amazonorder.TbBaseinfoSpczService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api/inter/tbBaseinfoSpcz")
public class ApiInterTbBaseinfoSpczController {

	@Autowired
	private CommonApiService<TbBaseinfoSpcz> commonApiService;
	@Autowired
	private TbBaseinfoSpczService tbBaseinfoSpczService;

	/**
	 * 查询
	 */
	@RequiresPermissions("tbBaseinfoSpcz:view")
	@RequestMapping("/search")
	@ResponseBody
	public LayuiTableVoJA search(@ModelAttribute TbBaseinfoSpcz cond) {
		return commonApiService.searchLay(cond);
	}
	
	@RequestMapping("/searchForDropdown")
	@ResponseBody
	public R searchForDropdown(String name) {
		
		TbBaseinfoSpcz cond = new TbBaseinfoSpcz();
		cond.setFields("A.Id value,concat(A.MaterialCn,'/',A.MaterialEn) name")
			.where(name != null && name.length() > 0 ? "A.MaterialCn like '%" + name + "%'" : "1=1")
			.setOrderby("A.Id desc");
		
		return commonApiService.searchForDropdown(cond);
	}

	/**
	 * 新增
	 */

	@PostMapping("/add")
	@ResponseBody
	public R add(@RequestParam Map<String, Object> params) {

		return tbBaseinfoSpczService.add(params);
	}

	/**
	 * 修改
	 */
	@RequiresPermissions("tbBaseinfoSpcz:edit")
	@PostMapping("/edit")
	@ResponseBody
	public R edit(@RequestParam Map<String, Object> params) {

		return tbBaseinfoSpczService.edit(params);
	}


	/**
	 * 删除
	 */
//	@RequiresPermissions("tbBaseinfoSpcz:delete")
	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, Long id) {

		try {
			tbBaseinfoSpczService.deleteTbBaseinfoSpcz(id);
			return R.ok("删除成功!");
		}catch (Exception e){
			e.printStackTrace();
			return R.error("删除失败，请稍后重试！");
		}

	}
	/**
	 * 弹出框调用
	 */
	@RequiresPermissions("tbBaseinfoSpcz:view")
	@RequestMapping("/searchForModal")
	@ResponseBody
	public LayuiTableVoJA searchForModal(@ModelAttribute TbBaseinfoSpcz cond){
		cond.setStatus(1);
		return commonApiService.searchLay(cond);
	}
}


